feat(cmd): wire --agent flag into new/yolo/yolo!/safe#27
Merged
Conversation
Wires `--agent <name>` through cmd/new.go and cmd/yolo_runners.go into createAndAttach -> SpawnOpts.Agent. Empty value falls through to session.DefaultAgent; unknown agents fail fast with a list of registered names so users can correct the flag. Closes the gap shipped (claimed but not delivered) in #25: README and CHANGELOG both promised `ctm new --agent codex` and `ctm new --agent hermes` but the cobra flag was never wired. The Agent registry, hermes package, and SpawnOpts.Agent field were already in place — this PR is purely the CLI surface. Tests cover empty / registered / unknown agent cases via the new resolveAgent helper. Suite count goes 410 -> 413.
Sonar's duplication gate (10.3% > 3% on new code) flagged the 4x
repeated 'flag().String("agent", ...)' + 4x 'GetString + resolveAgent
+ err handling' blocks across new/yolo/yolo!/safe RunE bodies.
Extracted addAgentFlag (registers the flag) and agentFromCmd (reads
+ validates) into cmd/yolo.go. Each call site is now a single helper
call. resolveAgent stays separate so the unit tests in
yolo_helpers_test.go still exercise the validation logic without
needing a cobra.Command in scope.
Sonar's coverage gate (77.8% < 80%) flagged the two thin wrappers added by the dedup refactor. Adds direct unit tests: - TestAddAgentFlag: registers + default value + usage text - TestAgentFromCmd_FlagUnset / _FlagSetValid / _FlagSetInvalid: read + validate flow on a fresh cobra.Command Helpers now at 100% coverage. Suite count goes 413 -> 417.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Summary
Adds the missing
--agent <name>cobra flag toctm new,ctm yolo,ctm yolo!, andctm safe. Closes a gap shipped in #25: README + CHANGELOG promisedctm new --agent codex/ctm new --agent hermes, but the cobra flag was never wired into the runners — every session gotsession.DefaultAgent.The Agent registry, hermes package, and
SpawnOpts.Agentfield were already in place. This PR is purely the CLI surface.How it works
Same for
ctm yolo/ctm yolo!/ctm safe.Files changed
cmd/yolo.goresolveAgent(name)helper — empty → empty (caller falls back), registered → name verbatim, unknown → error listingagent.Registered(). Addsinternal/agent+stringsimports.cmd/new.go--agentflag in init; read + validate + pass to createAndAttach.cmd/yolo_runners.go--agenton yoloCmd/yoloBangCmd/safeCmd; read + validate + pass to createAndAttach in all three runners.cmd/attach.gocreateAndAttachsignature gainsagentName stringbetween mode and store. The barectmrunAttach call passes""(no flag on root). SpawnOpts gets the Agent field set.cmd/yolo_helpers_test.goresolveAgent: empty path, registered names, unknown agent error format. Adds blank imports for codex+hermes so the registry is populated when tests run in thecmdpackage alone.CHANGELOG.md### Addedbullet for the--agentflag, ahead of the existing hermes entry.Test plan
go test ./...— 413 pass (was 410, +3 from newresolveAgenttests)go vet ./...cleango build ./...cleanctm new --helpandctm yolo --helpnow show--agent stringwith descriptionctm new x /tmp --agent nope→Error: unknown agent "nope"; available: codex, hermes--agent codexstampsagent: \"codex\"and--agent hermesstampsagent: \"hermes\"insessions.jsonctm new mytask ~/proj --agent codex→ verify codex spawns;ctm new mytask2 ~/proj --agent hermes→ verify hermes spawns. (Deferred to reviewer — needs interactive tmux.)Risks / notes
ctm new --agent <x>previously — that flag was silently ignored before (cobra rejects unknown flags by default, so the call would already error). No silent-misbehavior risk.cmd/attach.go'srunAttach(barectm <name>) does NOT take an--agentflag — it attaches to existing sessions by name; the agent is determined by the stored session row. Correct behavior, but worth flagging if you want the bare command to grow the flag later.gofmt -lstill shows pre-existing import-block drift incmd/new.goand other cmd files. Left untouched per scope discipline (same as PR feat(agent): add hermes agent support #25 and feat(session): flip DefaultAgent to hermes #26).🤖 Generated with Claude Code